import java.util.Scanner;

/**
 * @author gao
 * @date 2025/7/9 9:12
 */

public class Demo5 {
    private static Object locker = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            System.out.println("t1等待之前");
            synchronized (locker) {
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("t1等到之后");
        });

        Thread t2 = new Thread(() -> {
            Scanner in = new Scanner(System.in);
            System.out.println("请输入任意内容，唤醒t1");
            in.next();
            // 必须是同一个锁对象
            synchronized (locker) {
                locker.notify();
            }
        });

        t1.start();
        t2.start();
    }
}